<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../common.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'registerEdit.jsp' starting page</title>
    <script type="text/javascript" src="${path}/js/public/autocomplete.js"></script>
    
    <style type="text/css">
		.normalKw {
			width: 280px;
			height: 24px;
			line-height:22px; 
			border: #836FFF 2px solid;
			background:url(${path}/images/search_bg.gif) no-repeat 3px center #fff; 
			padding-left: 22px;
			margin-right: 8px;
			vertical-align: middle;
		}
		.foucsKw {
			width: 280px;
			height: 24px;
			line-height:19px;
			border: #836FFF 3px solid;
			background:url(${path}/images/search_bg.gif) no-repeat 3px center #fff; 
			padding-left : 22px;
			margin-right: 8px;
			vertical-align:middle; 
		}
		
		*{
			font-size: 12px;
		}
	</style>
	
	<script>
	
		/*添加水印效果*/
		function addWaterMark(obj) {
			obj.className = 'normalKw';
			
			if(!obj.value) {
				obj.value = "医疗卡/姓名/证件号";
				obj.style.color = 'gray';
			}
		}

		/*去除水印效果*/
		function removeWaterMark(obj) {
			obj.className = 'foucsKw';
			
			if(obj.value == "医疗卡/姓名/证件号") {
				obj.value = "";
				obj.style.color = '#000000';
			}
		}
		
		var person_name = null;
		
		$().ready(function() {
			//增加水印
			addWaterMark(document.all.keyword);
			$('#keyword').autocomplete(
				"${path}/auto?method=getPersonList",
				{
					max : 6, //列表里的条目数 
					minChars : 1, //自动完成激活之前填入的最小字符 
					width : 550, //提示的宽度，溢出隐藏 
					scrollHeight : 300, //提示的高度，溢出显示滚动条 
					matchContains : false, //包含匹配，就是data参数里的数据，是否只要包含文本框里的数据就显示 
					autoFill : false, //自动填充 
					parse: function(data){    
	                	var rows = [];
                        var d = data;  
                        for(var i=0; i<d.length; i++){    
                        	rows[rows.length] = {    
                            	data:d[i], //每条数据对象   
                           	 	value:d[i].name+d[i].id_card+d[i].card_num, //与输入的值比较的数据  
                            	result:d[i].name  //选中的实际数据  
                        	};    
                        }   
                        return rows;    
                    },
					formatItem : function(row, i, max) {
						return  "<table><tr><td width='120px'>" + row.name + "</td><td width='210px'>证件号：" + (row.id_card ? row.id_card : "") + "</td><td>医疗卡号：" + (row.card_num ? row.card_num : "") + "</td></table>";
					},
					formatMatch : function(row, i, max) {
						return row.name;
					},
					formatResult : function(row) {
						return row.name;
					}
				}).result(function(event, row, formatted) {
					personId = row.id;
					//map.campus = "${sessionScope.session_user.campus}";
					ajax.remoteCall("com.system.dao.PersonDao:getPersonAndAmountById",[row.id+"","${sessionScope.session_user.campus}"],function(reply){
						var result = reply.getResult();
						person_name = result.name;
						//计算年龄
						var myDate = new Date();
						var now = myDate.getFullYear();
						if(result.birthday!=null){
							var birthYear = result.birthday.substr(0,4);
							var age = now - birthYear;
							$("#age").val(age);
						}
						$("#register_type").val(result.register_type);
						$("#register_charge_mark").val(result.register_charge);
						Form.bindForm("winForm",result);
						if(result.type == "0"){
							$("#type").val("学生");
						}else if(result.type == "1"){
							$("#type").val("教职工");
						}else if(result.type == "2"){
							$("#type").val("退休");
						}else if(result.type == "3"){
							$("#type").val("离休");
						}else{
							$("#type").val("其他");
						}
						if($("#holiday").attr("checked")){
							$("#register_charge").val("4");
						}else{
							$("#register_charge").val($("#register_charge_mark").val());
						}
						count();
					});
				});
		});
		
		
		var personId = null;
		
		function doSave()
    	{
			if(doCheck())
			{
				var map = Form.formToBean("winForm");
		 		map.personId = personId;
		 		map.status = "1";
		 		map.person_name = person_name;
		 		
		 		ajax.remoteCall("com.system.dao.RegisterDao:updatePublic",[map],function(reply){
		 			var result = reply.getResult();
		 			alert(result.value);
		 			if(result.type == "success")
		 			{
		 				var dlg = Dialog.getInstance("view");
		 	    		dlg.getParam("window").mygrid.reload();
		 	    		dlg.close();
		 			}
		 		});
			}
    	}
		
		function doCheck()
		{
			if(!check_integer($.trim($("#book_amount").val())))
			{
				alert("病历本费用必须是数字");
				return false;
			}
			
			if(personId == null)
			{
				alert("请选择一个病人");
				return false;
			}
			return true;
		}
    	
    	function count(){
			//验证病历本输入内容
			var amount = parseInt($("#register_charge").val()) + parseInt($("#book_amount").val());
			if(isNaN(amount))
			{
				$("#amount").val();
			}else{
				$("#amount").val(amount);
			}
		}
		
		function ifHoliday(){
			if($("#holiday").attr("checked")){
				$("#register_charge").val("4");
				count();
			}else{
				$("#register_charge").val($("#register_charge_mark").val());
				count();
			}
		}
	</script>
  </head>
  
  <body style="overflow: hidden;">
   <form id="winForm" name="winForm">
   		<input id="personId" name="personId" type="hidden">
   		<input id="register_type" name="register_type" type="hidden">
   		<input id="currentUserName" name="currentUserName" type="hidden" value="${currentUserName}">
   		<input id="create_user_id" name="create_user_id" type="hidden" value="${currentUserId}">
   		<input id="currentUserCampus" name="currentUserCampus" type="hidden" value="${currentUserCampus}">
   		<input id="register_charge_mark" name="register_charge_mark" type="hidden">
	<table border="0" cellpadding="0" cellspacing="0" width="610" align="left">
		<tr>
			<td height="60" align="center" valign="middle" style="padding-top:5px;" colspan="3">
				<input type="text" id="keyword" name="keyword" class="normalKw" onfocus="removeWaterMark(this);" onblur="addWaterMark(this);" style="width:550px;height:30px;"></input>
			</td>	
		</tr>
		
		<tr>
			<td>
				<fieldset>
					<legend><font color='#3A5FCD' size='2'><b>基本信息</b></font></legend>
					<table>
						<tr>
							<td height="30" width="200" valign="middle" align="center">
								<font style="margin-left:0.6cm">姓名：</font>
								<input name="name" id="name" class="textbox" style="width:120px;" readonly/>
							</td>
							<td height="30" width="220" valign="middle" align="center">
								<font style="margin-left:0.6cm">性别：</font>
								<input name="sex" id="sex" class="textbox" style="width:140px;" readonly/>
							</td>
							<td height="30" width="200" valign="middle" align="center">
								<font style="margin-left:0.3cm">年龄：</font>
								<input name="age" id="age" class="textbox" style="width:120px" readonly/>
							</td>
						</tr>
						<tr>
							<td height="30" width="200" valign="middle" align="center">
								出生年月：<input name="birthday" id="birthday" class="textbox" style="width:120px" readonly/>
							</td>
							<td height="30" width="220" valign="middle" align="center">
								身份证号：<input name="id_card" id="id_card" class="textbox" style="width:140px" readonly/>
							</td>
							<td height="30" width="200" valign="middle" align="center">
								<font style="margin-left:0.3cm">校区：</font>
								<input name="campus" id="campus" class="textbox" style="width:120px" readonly/>
							</td>
						</tr>
						<tr>
							<td height="30" width="200" valign="middle" align="center">
								医保卡号：<input name="medicareCard" id="medicareCard" class="textbox" style="width:120px" readonly/>
							</td>
							<td height="30" width="220" valign="middle" align="center">
								病人类型：<input name="type" id="type" class="textbox" style="width:140px" readonly/>
							</td>
							<td height="30" width="200" valign="middle" align="center">
								社保编号：<input name="spendSum" id="spendSum" class="textbox" style="width:120px" readonly/>
							</td>
						</tr>
						<tr>
							<td height="30" width="200" valign="middle" align="center">
								班级/部门：<input name="class" id="" class="textbox" style="width:120px" readonly/>
							</td>
						</tr>
					</table>
				</fieldset>
			</td>
		</tr>
		<tr>
			<td>
				
				<fieldset>
					<legend><font color='#3A5FCD' size='2'><b>费用小计</b></font></legend>
					<table>
						<tr>
							<td height="60" width="120" valign="middle" align="center"><input id="holiday" name="holiday" type="checkbox" onclick="ifHoliday()"/>&nbsp;&nbsp;&nbsp;是否节假日</td>
							<td height="60" width="150" valign="middle" align="center">
								<font style="margin-left:0.3cm">挂号费：</font>
								<input name="register_charge" id="register_charge" class="textbox" readonly style="width:70px" />
							</td>
							<td height="60" width="150" valign="middle" align="center">
								<font style="margin-left:0.3cm">病历本：</font>
								<input name="book_amount" id="book_amount" onkeyup="count()" class="textbox"  style="width:70px" />
							</td>
							<td height="60" width="150" valign="middle" align="center">
								<font style="margin-left:0.3cm">小计：</font>
								<input name="amount" id="amount" readonly class="textbox" style="width:70px" />
							</td>
						</tr>
					</table>
				</fieldset>
			</td>
		</tr>
	</table>
	</form>
  </body>
</html>
